import {
  Controller,
  Get,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { MessageIndexDto } from './message.dto';
import { MessageService } from './message.service';
import { UserModel } from '@/module/user/user.model';
import { User } from "@/common/auth/user.decorator";
import { getPager } from "@/common/pager-response";
import { MessageCountUnreadResult, MessageIndexResult } from "@/module/message/message.result";
import { UserAuthGuard } from "@/common/auth/user-auth.guard";
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";

@Controller('/v1/messages')
@ApiTags('Message')
export class MessageV1Controller {
  constructor(private readonly messageService: MessageService) {
  }

  @Get('/mine')
  @UseGuards(UserAuthGuard)
  @ApiOperation({ summary: '我的消息' })
  @ApiPaginatedOkResponse(MessageIndexResult)
  async indexMine(
    @Query() query: MessageIndexDto,
    @User() user: UserModel,
  ): Promise<PageResult<MessageIndexResult>> {
    const res = await this.messageService.indexMine(query, user);
    return getPager(...res);
  }

  @Get('/count-unread')
  @UseGuards(UserAuthGuard)
  @ApiOperation({ summary: '我的消息' })
  @ApiOkResponse({ type: MessageCountUnreadResult })
  async countUnread(
    @User() user: UserModel,
  ): Promise<MessageCountUnreadResult> {
    const res = await this.messageService.countUnread(user);
    return res;
  }
}
